package com.wuhan.template.module.find.fragment;

import android.os.Bundle;
import android.util.Log;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseFragment;
import com.wuhan.template.module.find.adapter.ZhengwuListAdapter;
import com.wuhan.template.module.find.bean.ZhengwuBean;
import com.wuhan.template.utils.EventMessage;
import com.wuhan.template.utils.OkHttpUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;


public class ZhengwuFragment extends BaseFragment {


    private List<ZhengwuBean.ListBean> list = new ArrayList<>();

    private String dataUrl;
    private ZhengwuListAdapter adapter;

    public ZhengwuFragment() {
    }


    @BindView(R.id.zw_list)
    PullToRefreshListView listView;

    @Override
    protected void initViews() {
        adapter = new ZhengwuListAdapter(getActivity(),list);
        listView.setAdapter(adapter);
    }

    @Override
    protected void getReqParams(Bundle bundle) {
        dataUrl = bundle.getString("dataUrl");
        OkHttpUtils.get(dataUrl, null);
    }


    @Override
    public void onGetResult(EventMessage message) {
        super.onGetResult(message);
      //  String result = "{" + message.result.substring(13);
        if (message.type.equals(dataUrl)) {
            Gson gson = new Gson();
            ZhengwuBean zhengwuBean = gson.fromJson(message.result, ZhengwuBean.class);
            list.addAll(zhengwuBean.getList());
            adapter.notifyDataSetChanged();

            //List<Map<String,String>> maps = (List<Map<String, String>>) list.get(0).getIndexpic();


           /* ZhengwuBean.ListBean.IndexpicBean indexpic =
                    (ZhengwuBean.ListBean.IndexpicBean) zhengwuBean.getList().get(0).getIndexpic();
            Log.*//*e("ZhengwuFragment", indexpic.getHost() + indexpic.getDir() + indexpic.getFilepath() + indexpic.getFilename());
        */}
    }

    @Override
    protected int getLayoutId() {
        return R.layout.frag_zhengwu_layout;
    }
}
